{include file="Public:header2"/}

<body>
<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body">
            <xblock>
                <div style="padding-bottom: 10px;">
                    <a class="layui-btn" href="{:url('/admin/seckill_add')}">添加时间段</a>
                    <a style="text-decoration:none" title="操作" onClick="status_update('',2)" class="layui-btn layui-btn-danger">批量删除</a>
                    <span style="line-height:40px;float:right;">共有数据： {$count}条</span>
                </div>
            </xblock>
            <table class="layui-table" style="text-align:center">
                <thead>
                <tr>
                    <th style="width: 20px"><input  type="checkbox" class="all-check" /></th>
                    <th class="ccc">ID</th>
                    <th class="ccc">分类名称</th>
<!--                    <th class="ccc">限购数量</th>&lt;!&ndash;&ndash;&gt;-->
                    <th class="ccc">操作</th>
                </tr>
                </thead>
                <tbody>
                    {volist name="list" id="vo"}
                        <tr>

                            <td><input type="checkbox"  class="shell-check Keys" Key="{$vo['id']}"/></td>
                            <td>{$vo['id']}</td>
                            <td>{$vo['seckill_time']}</td>
                            <td>
                                <a style="text-decoration:none" title="编辑" href="{:url('/admin/seckill_edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-xs">
                                    <i class="layui-icon layui-icon-edit"></i>编辑
                                </a>
                                <a style="text-decoration:none" title="操作" onClick="status_update({$vo.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
                            </td>
                        </tr>
                    {/volist}
                
                        {if condition="empty($list)"}
                            <tr><td colspan='10' style="text-align:center;">暂时没有数据！</td></tr>
                        {/if}
                </tbody>
            </table>
            <div class="layui-box layui-laypage layui-laypage-default" style="margin-left:40%">
                {$page}
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
<script type="text/javascript">
    layui.use(['table'], function(){
        var $ = layui.$;
        var form = layui.form;        
        $(".all-check").click(function () {
            $(".shell-check").prop("checked", this.checked);
        });
        $(".shell-check").click(function () {
            var option = $(".shell-check");
            option.each(function (i) {
                if (!this.checked) {
                    $(".all-check").prop("checked", false);
                    return false;
                } else {
                    $(".all-check").prop("checked", true);
                }
            });
        });
    });

    //修改状态
    function status_update(id){
        layer.confirm('确认要执行当前操作吗？',function(){
            var url = "{:url('/admin/seckill_status')}";
            var load=layer.load(2);
            var $ = layui.$;
            var ids = []
            if (id == '') {
                $.each($('.Keys'), function (key, value) {
                    if ($(value).prop("checked")) {
                        ids.push(parseInt($(value).attr('Key')))
                    }
                })
            } else {
                ids.push(id)
            }
            if(ids.length <= 0){
                layer.msg('请选择数据',{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
                return false;
            }

            $.post(url,{"id":ids},function(data){
                if(data.status == 1){
                    layer.msg(data.msg,{icon:1,time:1000},function(){
                        location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                        layer.close(load);
                    });
                }
            })
        });
    }



</script>
</body>
</html>


